package com.example.mywebrtc;

import android.util.Log;

import org.webrtc.CandidatePairChangeEvent;
import org.webrtc.DataChannel;
import org.webrtc.IceCandidate;
import org.webrtc.MediaStream;
import org.webrtc.PeerConnection;
import org.webrtc.RtpReceiver;
import org.webrtc.RtpTransceiver;

public class PeerConnectionObserver implements PeerConnection.Observer {
    private final String LOCA_TAG = "PeerConnectionObserver";
    private String TAG;

    public PeerConnectionObserver(String TAG) {
        this.TAG = TAG;
    }

    @Override
    public void onSignalingChange(PeerConnection.SignalingState signalingState) {
        Log.i(LOCA_TAG, TAG + " signalingState " + signalingState.name());
    }

    @Override
    public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
        Log.i(LOCA_TAG, TAG + " onIceConnectionChange " + iceConnectionState.name());
    }

    @Override
    public void onStandardizedIceConnectionChange(PeerConnection.IceConnectionState newState) {
        Log.i(LOCA_TAG, TAG + " onStandardizedIceConnectionChange " + newState.name());
    }

    @Override
    public void onConnectionChange(PeerConnection.PeerConnectionState newState) {
        Log.i(LOCA_TAG, TAG + " onConnectionChange " + newState.name());
    }

    @Override
    public void onIceConnectionReceivingChange(boolean b) {
        Log.i(LOCA_TAG, TAG + " onIceConnectionReceivingChange " + b);
    }

    @Override
    public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
        Log.i(LOCA_TAG,TAG + " onIceGatheringChange " + iceGatheringState.name());
    }

    @Override
    public void onIceCandidate(IceCandidate iceCandidate) {
        Log.i(LOCA_TAG, TAG + " onIceCandidate " + iceCandidate.sdp);
    }

    @Override
    public void onIceCandidatesRemoved(IceCandidate[] iceCandidates) {
        Log.i(LOCA_TAG, TAG + " onIceCandidatesRemoved ");
    }

    @Override
    public void onSelectedCandidatePairChanged(CandidatePairChangeEvent event) {
        Log.i(LOCA_TAG, TAG + " onSelectedCandidatePairChanged " + event.reason);
    }

    @Override
    public void onAddStream(MediaStream mediaStream) {
        Log.i(LOCA_TAG, TAG + " onAddStream " + mediaStream.toString());
    }

    @Override
    public void onRemoveStream(MediaStream mediaStream) {
        Log.i(LOCA_TAG, TAG + " onRemoveStream " + mediaStream.toString());
    }

    @Override
    public void onDataChannel(DataChannel dataChannel) {
        Log.i(LOCA_TAG, TAG + " onDataChannel " + dataChannel.label());
    }

    @Override
    public void onRenegotiationNeeded() {
        Log.i(LOCA_TAG, TAG + " onRenegotiationNeeded");
    }

    @Override
    public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
        Log.i(LOCA_TAG, TAG + " onAddTrack ");
    }

    @Override
    public void onTrack(RtpTransceiver transceiver) {
        Log.i(LOCA_TAG, TAG + " onTrack " + transceiver.getMid());
    }
}
